<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="../WEB-INF/jspf/controlesessao.jspf"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Alterar Componentes</title>
        <script type="text/javascript" src="../js/jquery.js" ></script>
        <script type="text/javascript" src="../js/jquery.validate.js"></script>
        <script type="text/javascript" src="../js/forms.js"></script>
        <script type="text/javascript" src="../js/jquery-ui-1.8.2.custom.min.js" ></script>
        <link rel="stylesheet" href="../css/ui-lightness/jquery-ui-1.8.2.custom.css">
    <link rel="stylesheet" href="../css/forms.css"></head>
    <script>
        $(document).ready(function(){
        $("#form").validate({
            rules: {
                id_area: {required: true,digits: true
                }
                ,desc_componente: {}
                ,carga_componente: {digits: true
                }
            },
            submitHandler: function(form) {
                salvar(form);
            }
        });
        $("#add").click(function(){
            var txt = $("#competencia option:selected").text();
            $("#ajax_dados").append("<input type='checkbox' name='id_competencia' value='" + $("#competencia").val()+"' checked/>"+txt+" <br>" );
            $("#ajax_dados").slideDown(300);
        });
    });
    </script>


    <body>

        <form name="form" id="form" method="post" action="update.jsp" >
            <div id="formulario">
                <fieldset><legend>Dados</legend>
                    <sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">SELECT  * FROM Componentes where id_componente=?
                        <sql:param value="${param.chave}"/>
                    </sql:query>
                    <c:forEach var="row" items="${query.rows}">
                        <input type="hidden" name="id_componente" size="10" maxlength="10" class="required" value="${row.id_componente}">
                        <p><label class="lbInput">Código </label>${row.codigo_componente}
                           
                        </p>
                        <p><label class="lbInput">Descrição<em>*</em></label>
                            <input type="text" name="desc_componente" size="50" maxlength="100" class="required" value="${row.desc_componente}">
                        </p>
                        <p><label class="lbInput">Carga Horária<em>*</em></label>
                            <input type="text" name="carga_componente" size="10" maxlength="10" class="required" value="${row.carga_componente}">
                        </p>
                        <p>
                            <sql:query var="quCompetencias" dataSource="jdbc/dbo_MicrosoftSQLServer">
                                SELECT  * FROM Competencias
                                order by desc_competencia
                            </sql:query>
                            <label class="lbInput">Competência</label>
                            <select id="competencia" name="competencia">
                                <option value="">Selecione uma opção</option>

                                <c:forEach var="competencias" items="${quCompetencias.rows}">
                                    <option value="${competencias.id_competencia}">${competencias.desc_competencia}</option>
                                </c:forEach>
                            </select>
                            <img id="add" src="../imagens/Add.png">
                        </p>
                        <div id="ajax_dados" style="display:block; border:0px solid black; width:600px">
                            <sql:query var="quComp" dataSource="jdbc/dbo_MicrosoftSQLServer" >
                                select c.*, desc_competencia
                                from Componentes_Competencias c
                                left join Competencias t on c.id_competencia=t.id_competencia
                                where c.id_componente=?
                                <sql:param value="${row.id_componente}"/>
                            </sql:query>
                            <c:forEach var="comp" items="${quComp.rows}">
                                <input type='checkbox' name='id_competencia' value="${comp.id_competencia}" checked/>${comp.desc_competencia}<br>
                            </c:forEach>
                        </div>
                    </c:forEach>
                    <p>
                        <input class="submit" type="submit" value="Salvar">
                        <input class="submit" type="button" value="Voltar" onclick="listar('fm_lista_Componentes.jsp')">
                    </p>
                    <div id="ajax_dados" style="display:block">
                    </div>
                    <div id="msg" style="display:none"></div>
                </fieldset>
            </div>
        <input type="hidden" id="token" name="token" value="${sessionScope.token}" /> </form>
    </body>
</html>
